<template>
  <div class="basefile">
    <!-- 按钮 -->
    
    <div class="btns">
      <el-form size="small" inline style="text-align: right">
        <el-form-item label="名称">
          <el-input v-model="param.fileName"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button   size="small"  type="primary" icon="el-icon-search" @click="loadBaseFile">搜索</el-button >
        </el-form-item>
      </el-form>
      <el-button type="primary" size="small" @click="toAddHandler"><i class="el-icon-upload el-icon--left"></i>新增</el-button>
    </div>
    <!-- /按钮 -->
    <!-- {{BaseFile}} -->
    <!-- 表格 -->
    <el-table size="small" :data="BaseFile">
      <el-table-column type="index" :index="1" label="序号"></el-table-column>
      <el-table-column label="ID" prop="id" align="center"></el-table-column>
      <el-table-column label="名称" prop="fileName" align="center"></el-table-column>
      <el-table-column label="组名" prop="groupName" align="center"></el-table-column>
      <el-table-column label="上传时间" prop="uploadTime" align="center"></el-table-column>
      <el-table-column label="扩展名" prop="extName" align="center"></el-table-column>
      <el-table-column label="文件大小" prop="fileSize" align="center"></el-table-column>
      <el-table-column label="文件类型" prop="fileType" align="center"></el-table-column>


         <!-- 定制插槽 -->
      <el-table-column label="操作" width="180" align="center">
        <template slot-scope="scope">
        <el-button type="danger" round size="small" icon="el-icon-delete" @click="deleteHandler(scope.row)"  >移除</el-button>
        <el-button type="success" round size="small" icon="el-icon-edit" @click="editHandler(scope.row)"  >修改</el-button>
        </template>
    </el-table-column>
    </el-table>

    <!-- /表格 -->
  </div>
</template>
<script>

import{get,del}from '@/utils/request'
export default {
    data(){
    return {
      param:{},
        //组件模板中需要的数据
      BaseFile:[]
    };
  }, 
  // 页面渲染的时候会调用的函数
  created(){
    this.loadBaseFile();
  },
 // 所有的方法
  methods:{
        editHandler(row){
      // 跳转到修改页面 （新增页面）
      // 携带当前行的数据
      this.$router.push({
        path:"/basefile/create",    //跳转的路由（前端）
        query:row   // 携带参数
      })
    },

    //删除
        deleteHandler(row) {
      this.$confirm("此操作将永久删除该数据, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
        let url = "http://121.196.106.124:8888/base_file/deleteById";
        del(url, { id: row.id }).then((resp) => {
          this.$message({ type: "success", message: resp.message });
          this.loadBaseFile();
        });
      });
    },
    //跳转
        toAddHandler() {
      this.$router.push("/basefile/create");
    },
    //

    loadBaseFile(){
      let url = 'http://121.196.106.124:8888/base_file/query'
      get(url,this.param).then((resp)=>{
        this.BaseFile = resp.data;
      })
    }
  }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<!--使用了scoped属性之后，父组件的style样式将不会渗透到子组件中，-->
<!--然而子组件的根节点元素会同时被设置了scoped的父css样式和设置了scoped的子css样式影响，-->
<!--这么设计的目的是父组件可以对子组件根元素进行布局。-->
<style scoped>
.btns{
  margin-bottom: 0.5em;
}
</style>